from django.views import View

from sportsground.utils import Req
from sportsground.utils.Res import Res
from sportsground.utils.views import LoginRequiredUser


class ImageView(LoginRequiredUser, View):
    """ 头像 """

    def get(self, request):
        """ 获取 """
        user = request.user.user
        image = user.getImage()
        return Res.Image(image)

    @Req.getJson
    def post(self, request):
        """ 修改 """
        image = request.FILES.get("image")
        user = request.user.user
        user.saveImage(image.file)

        return Res.Json(Res.OK)
